﻿using UnityEditor;
using UnityEngine;

namespace EditorExtension
{
    // 定制检查面板
    [CustomEditor(typeof(CustomEditorExample))]
    public class CustomEditorExampleInspector : Editor
    {
        CustomEditorExample mTarget
        {
            get
            {
                return target as CustomEditorExample;
            }
        }

        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            
            // HP
            Rect hpRect = GUILayoutUtility.GetRect(18, 18, "TextField"); // 自动获取一个区域
            EditorGUI.ProgressBar(hpRect, mTarget.HP, "HP"); // 绘制进度条
            
            // Range
            Rect rangeRect = GUILayoutUtility.GetRect(18, 18, "TextField");
            EditorGUI.ProgressBar(rangeRect, mTarget.Range, "Range");
            
            // TextArea
            EditorGUILayout.BeginHorizontal("box");
            {
                EditorGUILayout.LabelField("角色名：", GUILayout.Width(200));
                mTarget.RoleName = EditorGUILayout.TextArea(mTarget.RoleName);
            }
            EditorGUILayout.EndHorizontal();
            
            
            // GameObj
            SerializedProperty otherObjProperty = serializedObject.FindProperty("OtherObj"); // 查找属性
            EditorGUILayout.ObjectField(otherObjProperty); // 绘制Inspector
            serializedObject.ApplyModifiedProperties(); // 提交修改的属性
        }
    }
}